Skip to content

refactor: update BaseConstraint.php to PHP 7.2 language level #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025

Conversation

DannyvdSluijs
Copy link
Collaborator

This pull request refactors the BaseConstraint class in the JsonSchema package to improve code readability, enforce immutability, and align with modern PHP practices. The changes include replacing anonymous functions with static closures, updating type casting, and removing outdated comments.

Code modernization and immutability:

  • Replaced anonymous functions with static closures in methods like addError, addErrors, and convertJsonPointerIntoPropertyPath to enforce immutability and improve performance. [1] [2] [3]
  • Updated type casting for better readability and adherence to modern PHP conventions, e.g., (string) instead of strval.

Code readability and cleanup:

  • Removed outdated docblock comments and unnecessary annotations, such as the @return tag in convertJsonPointerIntoPropertyPath.
  • Replaced \JSON_ERROR_NONE with the JSON_ERROR_NONE constant for consistency with the use statement.

Other improvements:

  • Adjusted the json_decode call to explicitly set the associative parameter to false for clarity.

@DannyvdSluijs DannyvdSluijs force-pushed the update-base-constraint-class branch from 846cbf8 to 2b6058b Compare May 7, 2025 19:52
@DannyvdSluijs DannyvdSluijs merged commit abfeca9 into master May 7, 2025
16 checks passed
@DannyvdSluijs DannyvdSluijs deleted the update-base-constraint-class branch May 7, 2025 19:55
DannyvdSluijs added a commit that referenced this pull request May 7, 2025
This pull request refactors the `BaseConstraint` class in the
`JsonSchema` package to improve code readability, enforce immutability,
and align with modern PHP practices. The changes include replacing
anonymous functions with static closures, updating type casting, and
removing outdated comments.

### Code modernization and immutability:

* Replaced anonymous functions with `static` closures in methods like
`addError`, `addErrors`, and `convertJsonPointerIntoPropertyPath` to
enforce immutability and improve performance.
[[1]](diffhunk://#diff-05cd63f6b003f185a215e10402525e33d94466ec4d83a685c5a6ccd1befcf921L53-R48)
[[2]](diffhunk://#diff-05cd63f6b003f185a215e10402525e33d94466ec4d83a685c5a6ccd1befcf921L81-R75)
[[3]](diffhunk://#diff-05cd63f6b003f185a215e10402525e33d94466ec4d83a685c5a6ccd1befcf921L167-R162)
* Updated type casting for better readability and adherence to modern
PHP conventions, e.g., `(string)` instead of `strval`.

### Code readability and cleanup:

* Removed outdated docblock comments and unnecessary annotations, such
as the `@return` tag in `convertJsonPointerIntoPropertyPath`.
* Replaced `\JSON_ERROR_NONE` with the `JSON_ERROR_NONE` constant for
consistency with the `use` statement.

### Other improvements:

* Adjusted the `json_decode` call to explicitly set the `associative`
parameter to `false` for clarity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant